import random
import time
import sys
Command = "abc"#设置用户命令输入
money = 100 #初始金钱
day = 0
Number_Potato = 0
Number_Cola = 0
Number_Beef = 0
Number_bread = 0
Number_Chips = 0
Number_Cola_Water = 0
Number_hamburger = 0
Need_hamburger = 0 #需求变量
Need_Chips = 0
Need_Cola_Water = 0
Money_Given = 0
Customer_Name = "Steve"
Done = 0
Rent_Money = 10
print("欢迎来到xiaowang2020的模拟经营游戏")
time.sleep(0.25)
print("由于不会写GUI 只能造个文字版\n")
time.sleep(0.25)
print("该游戏依赖命令输入框来操作\n")
time.sleep(0.25)
print("输入 \"start\" 来开始吧\n")
Command = str(input())
if Command != "start":
	print("Good Bye")
	sys.exit(0)
print("在这个游戏里 你需要购买食物原材料 烹饪它们 然后卖给你的顾客\n")
time.sleep(0.25)
print("一回合有60Ｓ 的时间限制 当你的时间用完 你会进入下一天\n")
time.sleep(0.25)
User_Name = str(input("输入你的用户名吧\n"))

def Enough_Check(had,need): #足够性检查
	if int(had) >= int(need):
		return True
	elif int(had) < int(need):
		return False
		
def Command_Check(command):#注 command为该函数内部形参
	command = str(command)
	global  Number_Potato
	global  Number_hamburger
	global  Number_Cola_Water
	global Number_Cola
	global Number_Chips
	global  Number_bread
	global  Number_Beef
	global  money
	global  Done
	if command == "help":
		print("help 请求帮助\n")
		print("stop 结束游戏\n")
		print("list 查看物品栏\n")
		print("buy <sth.> 购买食物的原材料\n")
		print("食物的原材料有 cola (汽水原酱)3元\n")
		print("potato (土豆)5元\n")
		print("beef (牛肉片)10元\n")
		print("bread (面包片)5元\n")
		print("make <sth.> chips薯条 cola water可乐 hamburger 汉堡")
		print("sell 当你的条件满足客户需求时 用sell卖出")
		print("剩余时间",roundtime - (time.time() - starttime))
		
	elif command == "stop":
		print("再见")
		sys.exit(0)
		
	elif command == "list":
		print("原材料 土豆 可乐原浆	 牛肉片 面包")
		print("    ",Number_Potato," ",Number_Cola," ",Number_Beef," ",Number_bread,"\n")
		print("成品 薯条数 可乐数 汉堡数")
		print("   ",Number_Chips," ",Number_Cola_Water," ",Number_hamburger,"\n")
		print("剩余时间",roundtime - (time.time() - starttime))
		
	elif command == "buy potato":
		print("正在购买土豆")
		if Enough_Check(money,5) == True:
			time.sleep(5)
			Number_Potato = Number_Potato + 1
			money = money - 5
			print("购买完成")
			print("当前金钱:",money)
			print("剩余时间",roundtime - (time.time() - starttime))
		elif  Enough_Check(money,5) == False:
			print("金额不足")
			print("当前金钱:",money)
			print("剩余时间",roundtime - (time.time() - starttime))
			
	elif command == "buy beef":
		print("正在购买牛肉片")
		if Enough_Check(money,10) == True:
			time.sleep(4)
			Number_Beef = Number_Beef + 1
			money = money - 10
			print("购买完成")
			print("当前金钱:",money)
			print("剩余时间",roundtime - (time.time() - starttime))
		elif Enough_Check(money,10) == False:
			print("金额不足")
			print("当前金钱:",money)
			print("剩余时间",roundtime - (time.time() - starttime))
			
	elif command == "buy cola":
		print("正在购买汽水原酱")
		if Enough_Check(money,3) == True:
			time.sleep(6)
			Number_Cola = Number_Cola + 1
			money = money - 3
			print("购买完成")
			print("当前金钱:",money)
			print("剩余时间",roundtime - (time.time() - starttime))
		elif Enough_Check(money,3) == False:
			print("金额不足")
			print("当前金钱:",money)
			print("剩余时间",roundtime - (time.time() - starttime))
			
	elif command == "buy bread":
		print("正在购买面包")
		if Enough_Check(money,5) == True:
			time.sleep(3)
			Number_bread = Number_bread + 1
			money = money - 5;
			print("购买完成")
			print("当前金钱:",money)
			print("剩余时间",roundtime - (time.time() - starttime))
		elif Enough_Check(money,5) == False:
			print("金额不足")
			print("当前金钱:",money)
			print("剩余时间",roundtime - (time.time() - starttime))
			
	elif command == "make cola water":
		print("正在制作可乐")
		if Enough_Check(Number_Cola,1) == True:
			time.sleep(1)
			Number_Cola_Water = Number_Cola_Water + 1
			Number_Cola = Number_Cola - 1
			print("制作完成")
			print("剩余时间",roundtime - (time.time() - starttime))
		elif Enough_Check(Number_Cola,1) == False:
			print("可乐原酱不足，请检查数量")
			print("剩余时间",roundtime - (time.time() - starttime))
			
	elif command == "make chips":
		print("正在制作薯条")
		if Enough_Check(Number_Potato,1) == True:
			time.sleep(6)
			Number_Chips = Number_Chips + 1
			Number_Potato = Number_Potato - 1
			print("制作完成")
			print("剩余时间",roundtime - (time.time() - starttime))
		elif Enough_Check(Number_Potato,1) == False:
			print("土豆不足，清检查土豆数量")
			print("剩余时间",roundtime - (time.time() - starttime))

	
	elif command == "make hamburger":
		print("正在制作汉堡")
		if Enough_Check(Number_bread,1) == True and Enough_Check(Number_Beef,1) == True:
			time.sleep(15)
			Number_hamburger = Number_hamburger + 1
			Number_bread = Number_bread - 1
			Number_Beef = Number_Beef - 1
			print("制作完成")
			print("剩余时间",roundtime - (time.time() - starttime))
		elif Enough_Check(Number_bread,1) == True and Enough_Check(Number_Beef,1) == False:
			print('汉堡原材料不足')
			print("剩余时间",roundtime - (time.time() - starttime))
			
	elif command == "sell":
		if Enough_Check(Number_hamburger,Need_hamburger) == True and Enough_Check(Number_Chips,Need_Chips) == True and Enough_Check(Number_Cola_Water,Need_Cola_Water) == True:
			Number_hamburger = Number_hamburger - Need_hamburger
			Number_Chips = Number_Chips - Need_Chips
			Number_Cola_Water = Number_Cola_Water - Need_Cola_Water 
			money = money + Money_Given
			Done = 1
			print('出售成功')
			print("当前金钱:",money)
			print("剩余时间",roundtime - (time.time() - starttime))
		else:
			print("出售失败，请检查原料数量")
			print("剩余时间",roundtime - (time.time() - starttime))
			
def Customers_Find(number):
	global  Customer_Name
	global  Need_hamburger
	global  Need_Cola_Water
	global  Need_Chips
	if number == 1:
		Customer_Name = "张三"
		Need_hamburger = 1
		Need_Cola_Water = 1
		Need_Chips = 1
		Money_Given = 35
	elif number == 2:
		Customer_Name = "李四"
		Need_hamburger = 2
		Need_Cola_Water = 1
		Need_Chips = 0
		Money_Given = 50
	elif number == 3:
		Customer_Name = "王二麻子"
		Need_hamburger = 0
		Need_Cola_Water = 1
		Need_Chips = 0
		Money_Given = 10
	elif number == 4:
		Customer_Name = "杨哲"
		Need_hamburger = 3
		Need_Cola_Water = 1
		Need_Chips = 2
		Money_Given = 100
	elif number == 5:
		Customer_Name = "刻晴"
		Need_hamburger = 1
		Need_Cola_Water = 1
		Need_Chips = 2
		Money_Given = 60
	elif number == 6:
		Customer_Name = "凝光"
		Need_hamburger = 1
		Need_Cola_Water = 0
		Need_Chips = 0
		Money_Given = 50
	elif number == 7:
		Customer_Name = "awfdaftyjvjhasd123"
		Need_hamburger = 1
		Need_Cola_Water = 12
		Need_Chips = 0
		Money_Given = 1200
		
		
	
starttime = time.time()
roundtime = 60

while money > 0:#判断游戏结束条件
	if roundtime - (time.time() - starttime) >= 0:
		print("用户名:",User_Name,"\n")
		print("生产天数:",day,"\n")
		while Done == 0 and roundtime - (time.time() - starttime) >= 0:
			Customers_Find(int(random.randint(1,7)))
			print("客户名：",Customer_Name,"\n")
			print("客户需求:\n",Need_Cola_Water,"个可乐\n",Need_Chips,"个薯条\n",Need_hamburger,"个汉堡\n")
			while Done == 0 and roundtime - (time.time() - starttime) >= 0:
				Command_Check(str(input("请输入指令，help请求帮助\n")))
				a = time.time() - starttime
		print("客户很满意")
		print("当前金钱:",money)
		print("剩余时间",roundtime - (time.time() - starttime))
		Done = 0
		
	elif roundtime - (time.time() - starttime) < 0:
		print("第",day,"天结束了\n")
		print("今日租金:",Rent_Money,"元\n")
		money = money - Rent_Money
		Rent_Money = Rent_Money + day * 2
		roundtime = roundtime + day * 10
		day = day + 1
print("游戏结束\n")
print("你经营了",day,"天")
		
		
		
		
